package com.leetcode.程序员面试金典.hard;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.stream.Collectors;

/**
 * @author 覃国强
 * @date 2022-02-19 17:20
 */
public class 面试题_17_25_单词矩阵 {

  public static void main(String[] args) {
    String[] words = {"this", "real", "hard", "trh", "hea", "iar", "sld"};
    Solution solution = new Solution();
    solution.maxRectangle(words);
  }

  static
  class Solution {
    public String[] maxRectangle(String[] words) {


      // 分组
      Map<Integer, List<String>> wordGroup = Arrays.stream(words).collect(Collectors.groupingBy(String::length));
      System.out.println(wordGroup);

      // 辅助 map
      Map<Character, Map<Character, Map<Integer, List<String>>>> map = new HashMap<>();
      for (String word : words) {
        int length = word.length();
        char start = word.charAt(0);
        char end = word.charAt(length - 1);
        if (!map.containsKey(start)) {
          map.put(start, new HashMap<>());
        }
        Map<Character, Map<Integer, List<String>>> secondMap = map.get(start);
        if (!secondMap.containsKey(end)) {
          secondMap.put(end, new HashMap<>());
        }
        Map<Integer, List<String>> threeMap = secondMap.get(end);
        if (!threeMap.containsKey(length)) {
          threeMap.put(length, new ArrayList<>());
        }
        threeMap.get(length).add(word);
      }


      for (Entry<Integer, List<String>> entry : wordGroup.entrySet()) {
        int width = entry.getKey();
        List<String> curWords = entry.getValue();
        for (int top = 0; top < curWords.size(); ++top) {
          for (int bottom = 0; bottom < curWords.size(); ++bottom) {
            for (int height = curWords.size(); height > 0; --height) {

              String topWord = curWords.get(top);
              String bottomWord = curWords.get(bottom);

              char s1 = topWord.charAt(0);
              char e1 = bottomWord.charAt(0);
              char s2 = topWord.charAt(width - 1);
              char e2 = bottomWord.charAt(width - 1);

              // 存在左边界的单词


              if (map.containsKey(s1) && map.get(s1).containsKey(s2) && map.get(s1).get(s2).containsKey(height)) {

              }



            }
          }
        }





      }



return null;

    }
  }

}
